# Api中间件层, 所以关于Api的请求都必须经过此中间件
from django.utils.deprecation import MiddlewareMixin
from django.conf import settings

from BloodSpiderWeb.views import urls as web_urls

class PathManage(MiddlewareMixin):
    def process_request(self, request):
        if request.path.startswith('/web/'):
            # 将urlpatterns转换为包含pattern和name属性的字典列表
            request.web_navs = []
            for path_obj in web_urls.urlpatterns:
                # 提取path字符串
                pattern = str(path_obj.pattern)
                # 提取name属性
                name = path_obj.name
                
                request.web_navs.append({
                    'pattern': pattern,
                    'name': name
                })
        return None
    def process_response(self, request, response):

        return response



